/*********************************** (C) COPYRIGHT ******************************
 * address: https://gitee.com/liuniansihuo/multitasks-os
 *
 * Change Logs:
 * Date			Author      	Notes
 * 2022-09-02	LiuHuo			first version
 *
*******************************************************************************/
#include "work_base.h"
/*
* function：默认添加工作队列队尾
* param:
	function：函数指针
	data: 函数的参数，可以是任何类型，强制转换即可
* return :
*/
void work_base_add_tail(struct WorkQueue_s * work,void (*function)(unsigned int data),unsigned int data)
{
	unsigned int i=0;
	if(work->cnt >= work->size)
		return;

	if((unsigned int)function == 0)
		return;

	for(i=0; i < work->cnt; i++)
	{
		if((work->func[i].function == function) && (work->func[i].data == data))
			return;
	}
	work->func[work->cnt].function 	= function;
	work->func[work->cnt].data 		= data;
	work->cnt++;
}

/*
* function：删除指定的工作任务
* param:
	function：函数指针
	data: 函数的参数，可以是任何类型，强制转换即可
* return :
*/
void work_base_del(struct WorkQueue_s * work,void (*function)(unsigned int data), unsigned int data)
{
	unsigned int i=0;

	for(i=0; i<work->cnt; i++)
	{
		if(((unsigned int)work->func[i].function == (unsigned int)function) && (work->func[i].data == data))
		{
			work->cnt--;
			work->func[i].function = work->func[work->cnt].function;
			work->func[i].data = work->func[work->cnt].data;
			work->func[work->cnt].function = 0;
			work->func[work->cnt].data = 0;

			break;
		}
	}
}


